
%% Startup

close all
clear all
clc
tic

% EWRLNC Function header:
% function [I,P1,P2] = ewrlnc(nb_sims,gen_size,m,nb_transmissions,loss_prob,R1,R2,R3)

% Parameters to test EWRLNC for:
gen_size=9; % generation size
m=8; % 2^m = field size
nb_transmissions=20; % nb of send packets
nb_sims=1000; % simulations (Note: 100 sims take ~1 min, scales linearly)
loss_prob=0.2; % packet loss probability
R1=0.5; % probability of layer 1
R2=0.25; % Probability of layer 2
R3=0.25; % probability of layyer 3

%% Collect data

I_prob=[]; % vector which will hold probability of decoding I
P1_prob=[]; % vector which will hold probability of decoding P1
P2_prob=[]; % vector which will hold probability of decoding P2

% For various packet losses get probability that I,P1,P2 was recv.
for loss_prob = 0:0.1:1
    [I,P1,P2]=ewrlnc(nb_sims,gen_size,m,nb_transmissions,loss_prob,R1,R2,R3);
    I_prob=[I_prob;I/nb_sims];
    P1_prob=[P1_prob;P1/nb_sims];
    P2_prob=[P2_prob;P2/nb_sims];
end

%% Plotting

% quick fix of x vector - must be the same sequence as in for-loop
loss_prob=0:0.1:1;

% Setup Plot
hold on
plot(loss_prob,I_prob,'-*','Color','black')
plot(loss_prob,P1_prob,'-o','Color','black')
plot(loss_prob,P2_prob,'-d','Color','black')
hold off

% Plot Annotation
xlabel('Packet loss probability [-]')
ylabel('Probability of Decoding')
legend('I','P1','P2')
grid('on')

toc


